package com.wanmait.translate.system.controller;

import com.wanmait.translate.dto.ResultData;
import com.wanmait.translate.pojo.SystemMenu;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/system/menu/")
public class SystemMenuController extends SystemParentController {
    private Logger LOG = LoggerFactory.getLogger(SystemMenuController.class);

    /*
     * @Author huweibin
     * @Description 条件查询菜单，如果name为空则查询所有
     * @Date 21:33 2020/11/14
     **/
    @RequestMapping("list")
    public ResultData list(String name) {
        List<SystemMenu> list = systemMenuService.list(name);
        list.add(systemMenuService.getByPrimaryKey(0));
        LOG.info("菜单列表为" + list);
        return ResultData.SuccesssWithData(list);
    }
    /*
     * @Author huweibin
     * @Description 保存
     * @Date 0:13 2020/11/15
     **/
    @RequestMapping("save")
    public void save(SystemMenu menu) {

        if(menu.getEnable()==null){
            menu.setEnable(1);
        }
        if(menu.getVisible()==null){
            menu.setVisible(1);
        }
        if (menu.getId()==null){
            systemMenuService.save(menu);
        }else {
            if(menu.getId().equals(menu.getParentId())){
                return;
            }
            systemMenuService.update(menu);
        }
    }
    /**
     * @Author huweibin
     * @Description 删除
     * @Date 0:13 2020/11/15
     **/
    @RequestMapping("remove")
    public ResultData remove(Integer id) {
        return systemMenuService.remove(id);
    }
}
